<template>
  <div id="app">
    <header class="head">
      <a class="back tl" href="javascript:history.back(-1)">
        <i class="el-icon-arrow-left"></i>
      </a>
      <a href="javascript:;" class="tc">
        <small class="font_18 co_f">添加食品类别</small>
      </a>
      <a href="javascript:;" class="save">
        <button @click="submitForm()" type="primary">保存</button>
      </a>
    </header>
    <main>
      <div class="formcontent">
        <ul>
          <li>
            <span>人员类别</span>
            <div class="froms">
              <el-select v-model="formName.personType" placeholder="请选择">
                <el-option v-for="item in options" :key="item.value" :label="item.label" :value="item.value">
                </el-option>
              </el-select>
            </div>
          </li>
          <li>
            <span><em></em>姓名</span>
            <div class="froms">
              <input v-model="formName.name">
            </div>
          </li>
  
          <li>
            <span><em>*</em>职务</span>
            <div class="froms">
              <input v-model="formName.post" name="post" v-validate="'required'" :class="{'is-danger': errors.has('post')}">
            </div>
          </li>
          <li>
            <span><em>*</em>身份证号</span>
            <div class="froms">
              <input v-model="formName.idCard" name="idCard" v-validate="'required|numeric'" :class="{'is-danger': errors.has('idCard')}">
            </div>
          </li>
          <li>
            <span><em></em>工作职责</span>
            <div class="froms">
              <input v-model="formName.workDuty">
            </div>
          </li>
          <li>
            <span><em>*</em>联系手机</span>
            <div class="froms">
              <input v-model="formName.contactPhone" name="contactPhone" v-validate="'required|numeric'" :class="{'is-danger': errors.has('contactPhone')}">
            </div>
          </li>
          <li>
            <span><em>*</em>办公固话</span>
            <div class="froms">
              <input v-model="formName.officeTelePhone" name="officeTelePhone" v-validate="'required|numeric'" :class="{'is-danger': errors.has('officeTelePhone')}">
            </div>
          </li>
        </ul>
      </div>
  
    </main>
  </div>
</template>

<script>
  import {
    FuQingPersonAdd
  } from '../../../api/api'
  export default {
    name: 'FuQingPersonAdd',
    data() {
      return {
        options: [{
          value: '0',
          label: '日常经营管理负责人'
        }, {
          value: '1',
          label: '食品安全管理人员'
        }, {
          value: '2',
          label: '食品原料采购负责人'
        }, {
          value: '3',
          label: '厨房负责人（行政总厨）'
        }, {
          value: '4',
          label: '食品原料仓库负责人'
        }, {
          value: '5',
          label: '食品原料仓库负责人'
        }],
        formName: {
          personType: '',
          name: '',
          post: '',
          idCard: '',
          workDuty: '',
          contactPhone: '',
          officeTelePhone: '',
        }
      };
    },
    methods: {
      //提交方法
      submitForm: function() {
        this.$validator.validateAll().then((result) => {
          if (result) {
            let varQueryData = {
              Unid: JSON.parse(localStorage.getItem('auth')).enterpriseUnid
            }
            let data = {
              PersonType: this.formName.personType,
              Enterprise: varQueryData,
              Name: this.formName.name,
              Post: this.formName.post,
              IdCard: this.formName.idCard,
              WorkDuty: this.formName.workDuty,
              ContactPhone: this.formName.contactPhone,
              OfficeTelePhone: this.formName.officeTelePhone,
            }
            let dataoption = {
              params: {
                Data: JSON.stringify(data),
                UserUnid: JSON.parse(localStorage.getItem('auth')).UserUnid,
  
              }
            }
            //调取接口
            FuQingPersonAdd(dataoption).then((res) => {
              if (res.success === true) {
                this.$message.success('保存成功');
                this.$router.go(-1);
              } else {
                this.$message.error(res.msg);
              }
            }).catch(function() {
              this.$message.error('网络异常。');
            })
  
          } else {
              this.$message.error('带*号为必填项，请确认填写格式正确');
          }
        })
  
      },
      created() {
  
      },
    }
  }
</script>

<style lang="scss">
  
</style>
